<template>
  <div id="newDiscussList">
    <a-comment v-for="discussion in discussions" :key="discussion.id">
      <template #author><a>{{ discussion.author }}</a></template>
      <template #avatar>
        <a-avatar src="https://q2.qlogo.cn/headimg_dl?dst_uin=2924401655&spec=100&t=1745817007265" alt="Avatar" />
      </template>
      <template #content>
        <p style="text-overflow: ellipsis; max-height: 32px;">
          {{ discussion.content }}
        </p>
      </template>
      <template #datetime>
        <a-tooltip :title="discussion.time">
          <span>{{ formatTime(discussion.time) }}</span>
        </a-tooltip>
      </template>
    </a-comment>
  </div>
</template>

<script setup>
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';

dayjs.extend(relativeTime);

// 定义props
const props = defineProps({
  discussions: {
    type: Array,
    default: () => []
  }
});

// 格式化时间
const formatTime = (timeStr) => {
  return dayjs(timeStr).fromNow();
};
</script>

<style scoped></style>